add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xfpm-marshal.c
    COMMAND	glib-genmarshal
                --prefix=_xfpm_marshal --body
                ${CMAKE_CURRENT_SOURCE_DIR}/xfpm-marshal.list
                --output ${CMAKE_CURRENT_BINARY_DIR}/xfpm-marshal.c
)

add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xfpm-marshal.h
    COMMAND	glib-genmarshal
                --prefix=_xfpm_marshal --header
                ${CMAKE_CURRENT_SOURCE_DIR}/xfpm-marshal.list
                --output ${CMAKE_CURRENT_BINARY_DIR}/xfpm-marshal.h
)

add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xfce-power-manager-dbus.c
    COMMAND	gdbus-codegen
                --interface-prefix=org.vvxfce. --c-namespace=Xfpm
                --generate-c-code=xfce-power-manager-dbus
                ${CMAKE_CURRENT_SOURCE_DIR}/org.xfce.Power.Manager.xml
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

set(BUILT_SOURCES
        ${CMAKE_CURRENT_BINARY_DIR}/xfce-power-manager-dbus.c
        # ${CMAKE_CURRENT_BINARY_DIR}/xfce-power-manager-dbus.h
        ${CMAKE_CURRENT_BINARY_DIR}/xfpm-marshal.c
        ${CMAKE_CURRENT_BINARY_DIR}/xfpm-marshal.h
        org.freedesktop.PowerManagement.c
        org.freedesktop.PowerManagement.h
        org.freedesktop.PowerManagement.Inhibit.c
        org.freedesktop.PowerManagement.Inhibit.h
)

set(xfce4_power_manager_SOURCES
        ${BUILT_SOURCES}
        xfpm-main.c
        xfpm-manager.c
        xfpm-manager.h
        xfpm-power.c
        xfpm-power.h
        xfpm-battery.c
        xfpm-battery.h
        xfpm-xfconf.c
        xfpm-xfconf.h
        xfpm-console-kit.c
        xfpm-console-kit.h
        xfpm-systemd.c
        xfpm-systemd.h
        egg-idletime.c
        egg-idletime.h
        xfpm-backlight.c
        xfpm-backlight.h
        xfpm-kbd-backlight.c
        xfpm-kbd-backlight.h
        xfpm-dpms.c
        xfpm-dpms.h
        xfpm-button.c
        xfpm-button.h
        xfpm-network-manager.c
        xfpm-network-manager.h
        xfpm-inhibit.c
        xfpm-inhibit.h
        xfpm-notify.c
        xfpm-notify.h
        xfpm-polkit.c
        xfpm-polkit.h
        xfpm-errors.c
        xfpm-errors.h
        xfpm-suspend.c
        xfpm-suspend.h
        ../panel-plugins/power-manager-plugin/power-manager-button.c
        ../panel-plugins/power-manager-plugin/power-manager-button.h
        ../panel-plugins/power-manager-plugin/scalemenuitem.c
        ../panel-plugins/power-manager-plugin/scalemenuitem.h
)

add_executable(${PROJECT_NAME}
        ${xfce4_power_manager_SOURCES}
)

set(deps)
if (${IS_ALONE_COMPILE})
    list(APPEND deps PkgConfig::GIO)
    list(APPEND deps PkgConfig::GIO_UNIX)
    list(APPEND deps PkgConfig::GOBJECT)
    list(APPEND deps PkgConfig::GTHREAD)
    list(APPEND deps PkgConfig::XFCE4_UI)
    list(APPEND deps PkgConfig::XFCONF)
else()
    list(APPEND deps glib-shared)
    list(APPEND deps vvxfconf-0)
    list(APPEND deps libxfce4ui-2)
endif()


target_link_libraries(${PROJECT_NAME}
        PRIVATE
        vvxpm-common
        vvxpm-libdbus
        ${deps}
        PkgConfig::NOTIFY
        PkgConfig::XCB_DPMS
    	PkgConfig::DBUS_GLIB
    	PkgConfig::UPOWER_GLIB
    	PkgConfig::XRANDR
)
install(TARGETS ${PROJECT_NAME}
        DESTINATION bin
)

#xfce4_power_manager_LDFLAGS =			\
#	-no-undefined				\
#	$(PLATFORM_LDFLAGS)
#

#if ENABLE_POLKIT
#
#sbin_PROGRAMS = xfpm-power-backlight-helper     \
#	   xfce4-pm-helper
#

add_executable(vvxfpm-power-backlight-helper
      xfpm-backlight-helper.c
)

set(deps1)
if (${IS_ALONE_COMPILE})
    list(APPEND deps1 PkgConfig::GLIB)
else()
    list(APPEND deps1 glib-shared)
endif()
target_link_libraries(vvxfpm-power-backlight-helper
        PRIVATE
        ${deps1}
        -lm
)

install(TARGETS vvxfpm-power-backlight-helper
        DESTINATION sbin
)

add_executable(vvxfce4-pm-helper
        xfpm-pm-helper.c
)

set(deps2)
if (${IS_ALONE_COMPILE})
    list(APPEND deps2 PkgConfig::GLIB)
    list(APPEND deps2 PkgConfig::XFCE4_UTIL)
else()
    list(APPEND deps2 glib-shared)
    list(APPEND deps2 libxfce4util-shared)
endif()

target_link_libraries(vvxfce4-pm-helper
        PRIVATE
        ${deps2}
)

install(TARGETS vvxfce4-pm-helper
        DESTINATION sbin
)

#polkit_policydir = $(datadir)/polkit-1/actions
#polkit_policy_DATA =					\
#	org.xfce.power.policy
#

set(sbindir ${CMAKE_INSTALL_PREFIX}/sbin)
configure_file(
        ${CMAKE_CURRENT_SOURCE_DIR}/org.vvxfce.power.policy.in
        ${CMAKE_CURRENT_BINARY_DIR}/org.vvxfce.power.policy
        @ONLY
)

install(FILES
        ${CMAKE_CURRENT_BINARY_DIR}/org.vvxfce.power.policy
        DESTINATION /usr/share/polkit-1/actions
)

## You will need a recent intltool or the patch from this bug
## http://bugzilla.gnome.org/show_bug.cgi?id=462312
#@INTLTOOL_POLICY_RULE@
#
#.in2.in:
#	sed "s|[@]sbindir@|${sbindir}|" $< > $@
#
#endif
#
#manpagedir = $(mandir)/man1
#
#manpage_DATA = xfce4-power-manager.1
#

#
#if MAINTAINER_MODE
#
#xfpm-marshal.c: xfpm-marshal.list
#	echo "#include \"xfpm-marshal.h\"" > $@ && \
#	glib-genmarshal $< --prefix=_xfpm_marshal --body >> $@
#
#xfpm-marshal.h: xfpm-marshal.list
#	glib-genmarshal $< --prefix=_xfpm_marshal --header > $@
#
#xfce-power-manager-dbus.c xfce-power-manager-dbus.h: $(srcdir)/org.xfce.Power.Manager.xml
#	gdbus-codegen --interface-prefix=org.xfce. --c-namespace=Xfpm --generate-c-code=xfce-power-manager-dbus $<
#
#org.freedesktop.PowerManagement.c org.freedesktop.PowerManagement.h: $(srcdir)/org.freedesktop.PowerManagement.xml
#	gdbus-codegen --interface-prefix=org.freedesktop. --c-namespace=Xfpm --generate-c-code=org.freedesktop.PowerManagement $<
#
#org.freedesktop.PowerManagement.Inhibit.c org.freedesktop.PowerManagement.Inhibit.h: $(srcdir)/org.freedesktop.PowerManagement.Inhibit.xml
#	gdbus-codegen --interface-prefix=org.freedesktop. --c-namespace=Xfpm --generate-c-code=org.freedesktop.PowerManagement.Inhibit $<
#
#endif
#
#@INTLTOOL_DESKTOP_RULE@
#autostartdir = $(sysconfdir)/xdg/autostart
#autostart_in_files = xfce4-power-manager.desktop.in
#autostart_DATA = $(autostart_in_files:.desktop.in=.desktop)

set(_xfce4-power-manager_ ${CMAKE_INSTALL_PREFIX}/bin/${PROJECT_NAME})
configure_file(
        ${CMAKE_CURRENT_SOURCE_DIR}/vvxfce4-power-manager.desktop.in
        ${CMAKE_CURRENT_BINARY_DIR}/vvxfce4-power-manager.desktop
        @ONLY
)

install(FILES
        ${CMAKE_CURRENT_BINARY_DIR}/vvxfce4-power-manager.desktop
        DESTINATION /etc/xdg/autostart
)

install(FILES
        vvxfce4-power-manager.xml
        DESTINATION /etc/xdg/vvxfce4/vvxfconf/vvxfce-perchannel-xml/
)

#
#EXTRA_DIST =                                    \
#	xfpm-marshal.list			\
#        $(autostart_in_files)                   \
#        org.xfce.power.policy.in2              \
#        $(manpage_DATA)
#
#DISTCLEANFILES =                                \
#        xfce4-power-manager.desktop             \
#        org.xfce.power.policy                  \
#        org.xfce.power.policy.in
#
#MAINTAINERCLEANFILES =                                \
#        $(BUILT_SOURCES)
